$(function(){

})
function timestampToTime(timestamp) {
    var date = new Date(timestamp * 1000);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
    var Y = date.getFullYear() + '-';
    var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
    var D = date.getDate() + ' ';
    var h = date.getHours() + ':';
    var m = date.getMinutes() + ':';
    var s = date.getSeconds();
    return Y+M+D+h+m+s;
}
function news_nav(obj,id) {
	$(obj).addClass('bot-tis');
	$(obj).siblings().removeClass('bot-tis');
	var new_url = 'http://'+document.domain+"/index/data/newlist";
	$.ajax({
		type: 'POST',
        url: new_url,
        data:{cat:id},
        dataType: 'json',
        success: function(result){
        	var html = '';
			result.forEach((item,i)=>{
				html += '<div class="list">';
					html += '<a href="article.php?id='+result[i]['id']+'"><img src="'+result[i]['img']+'" class="img"></a>';
					html += '<div class="con">';
						html += '<a href="article.php?id='+result[i]['id']+'"><div class="title">'+result[i]['title']+'</div></a>';
						html += '<p>'+result[i]['abstract']+'</p>';
						html += '<div class="author">';
							html += '<div class="left">';
								html += '<img src="./images/201811200020216214-380x228.png" class="head_pic">';
								html += '<a href="author.php?id='+result[i]['user_id']+'" class="member_name">'+result[i]['member_name']+'</a>';
								html += '<img src="./images/dian.png" class="dian">';
								html += '<span>'+timestampToTime(result[i]['addtime'])+'</span>';
								html += '<img src="./images/dian.png" class="dian">';
								result[i]['label_v'].forEach((item,j)=>{
									html += '<a class="label" href="label.php?id='+result[i]['id']+'">'+result[i]['label_v'][j]['name']+'</a>';
								});
							html += '</div>';
							html += '<div class="right">';
								html += '<a href=""><img src="./images/zan.png"></a>';
								html += '<p>'+result[i]['like']+'</p>';
								html += '<img src="./images/eye.png">';
								html += '<p>'+result[i]['look']+'</p>';
								html += '<img src="./images/comment1.png">';
								html += '<p>'+result[i]['comments']+'</p>';
							html += '</div>';
						html += '</div>';
					html += '</div>';
				html += '</div>';
			})
			$('#news_list').html(html);
        },
	})
}

//获取url地址参数信息
function GetQueryString(name)
{
     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
     var r = window.location.search.substr(1).match(reg);
     if(r!=null)return  decodeURI(r[2]); return null;
}

//替换指定传入参数的值,paramName为参数,replaceWith为新值
function replaceParamVal(paramName,replaceWith) {
    var oUrl = this.location.href.toString();
    var re=eval('/('+ paramName+'=)([^&]*)/gi');
    var nUrl = oUrl.replace(re,paramName+'='+replaceWith);
    this.location = nUrl;
	window.location.href=nUrl
}
//搜索资讯
function searchArticle(search) {
	var searchArticle = 'http://'+document.domain+"/index/data/searchArticle";
	$.ajax({
		type: 'POST',
        url: searchArticle,
        data:{search:search},
        dataType: 'json',
        success: function(result){
        	var html = '';
			result.forEach((item,i)=>{
				html += '<div class="list">';
					html += '<a href="article.php?id='+result[i]['id']+'"><img src="'+result[i]['img']+'" class="img"></a>';
					html += '<div class="con">';
						html += '<a href="article.php?id='+result[i]['id']+'"><div class="title">'+result[i]['title']+'</div></a>';
						html += '<p>'+result[i]['abstract']+'</p>';
						html += '<div class="author">';
							html += '<div class="left">';
								html += '<img src="'+result[i]['head_pic']+'" class="head_pic">';
								html += '<a class="member_name" href="author.php?id='+result[i]['user_id']+'">'+result[i]['member_name']+'</a>';
								html += '<img src="./images/dian.png" class="dian">';
								html += '<span>'+timestampToTime(result[i]['addtime'])+'</span>';
								html += '<img src="./images/dian.png" class="dian">';
								result[i]['label_v'].forEach((item,j)=>{
									html += '<a class="label" href="label.php?id='+result[i]['id']+'">'+result[i]['label_v'][j]['name']+'</a>';
								});
							html += '</div>';
							html += '<div class="right">';
								html += '<a href=""><img src="./images/zan.png"></a>';
								html += '<p>'+result[i]['like']+'</p>';
								html += '<img src="./images/eye.png">';
								html += '<p>'+result[i]['look']+'</p>';
								html += '<img src="./images/comment1.png">';
								html += '<p>'+result[i]['comments']+'</p>';
							html += '</div>';
						html += '</div>';
					html += '</div>';
				html += '</div>';
			})
			$('#text1').html(html);
        },
	})
}
//搜索视频
function searchVideo(search) {
	var searchVideo = 'http://'+document.domain+"/index/data/searchVideo";
	$.ajax({
		type: 'POST',
        url: searchVideo,
        data:{search:search},
        dataType: 'json',
        success: function(result){
        	var html = '';
			result.forEach((item,i)=>{
				html += '<div class="text-con">';
					html += '<img src="'+result[i]['img']+'" class="img">';
					html += '<div class="text-name">123</div>';
					html += '<p><img src="./images/zan.png"> 123 &nbsp;&nbsp;<img src="./images/diss.png"> 123</p>';
				html += '</div>';
			})
			$('#text1').html(html);
        },
	})
}
//搜索作者
function searchWriter(search) {
	var searchWriter = 'http://'+document.domain+"/index/data/searchWriter";
	$.ajax({
		type: 'POST',
        url: searchWriter,
        data:{search:search},
        dataType: 'json',
        success: function(result){
        	var html = '';
			result.forEach((item,i)=>{
				html += '<div class="writer"><div class="member-pic"><img src="'+result[i]['head_pic']+'"><a href="" class="">关注</a></div><div class="member-list"><div class="title">'+result[i]['member_name']+'</div><div class="member_num"><ul><li>文章数</li><li>点击量</li><li>获赞数</li><li>评论数</li></ul></div><div class="member_num"><ul><li>'+result[i]['consult']+'</li><li>'+result[i]['browse']+'</li><li>'+result[i]['like']+'</li><li>'+result[i]['diss']+'</li></ul></div><div class="introduce">作者简介：'+result[i]['signature']+'</div></div><div class="member_article"><ul><li>当你说只能合约，你说到底是什么？</li><li>当你说只能合约，你说到底是什么？</li><li>当你说只能合约，你说到底是什么？</li><li>当你说只能合约，你说到底是什么？</li></ul></div></div>';
			})
			$('#text3').html(html)
        },
	})
}

//存Cookie
function setCookie(name, value) { 
    var exp = new Date(); 
    exp.setTime(exp.getTime() + 60 * 60 * 1000); 
    document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString() + ";path=/"; 
}
//读取cookies 
function getCookie(name) { 
    var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)"); 

    if (arr = document.cookie.match(reg)) 

        return unescape(arr[2]); 
    else 
        return null; 
}